<template>
  <div  class="clientInfo_wrapper">
    <el-row class="main">
      <el-col :span="12">
        <div class="clientInfo_box">
          <div class="item" v-for="(item, index) in details.rows" :key="index">
            <div class="info">
              <span class="label">{{item.name}}：</span>
              <span v-if="item.type == 'image'" class="text">
                <el-avatar size="large" :src="item.value"></el-avatar>
              </span>
              <span v-else-if="item.type == 'file'" class="text">
                {{ item.fileList[0].name ? item.fileList[0].name: '-' }}
              </span>
              <span v-else class="text">
                {{ item.value ? item.value: '-' }}
              </span>
            </div>
            <div class="btn">

              <el-button v-if="item.type == 'file'" size="small" type="primary" plain  @click="viewFile(item.value)" >查看</el-button>
              <el-button v-if="item.is_readonly < 1 && item.type != 'file'" size="small" type="primary" plain @click="handleEdit(item,index)">修改</el-button>
            </div>
          </div>

        </div>
      </el-col>

    </el-row>
    <el-dialog
      title="提示"
      append-to-body
      :center="true"
      :visible.sync="editDialog"
      width="50%"
    >
      <el-form ref="form" :model="details.rows" label-width="80px" style="text-align: center">
        <el-form-item label="标题" :prop="item.name"  v-for="(item, index) in details.rows" :key="index" v-if='edit_type == item.field'>
          <el-upload v-if='item.type == "image"'
            class="avatar-uploader"
            :action="apiUpload"
            :show-file-list="false"
            :multiple="false"
            :on-success="handleAvatarSuccess">
            <img v-if="item.value" :src="item.value" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <el-input v-else type='textarea' :rows="4" v-model="item.value"  />
        </el-form-item>
       <!-- <div v-for="(item, index) in details.rows" :key="index" v-if='edit_type == item.field'  class="dia_box">
          {{item.name}}：
          <el-input type='textarea' :rows="4" v-model="item.value"  />
        </div> -->

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialog = false">取 消</el-button>
        <el-button type="primary" @click="submit(edit_type)">确 定</el-button>
      </span>
    </el-dialog>


  </div>
</template>

<script>
import { resumeDetailsList, updateResume } from '@/api/resume_urm'
import { parseTime } from '@/utils'
import { classify } from '@/api/company_crm'
import { resumeImgDel } from '@/api/resume'
import { memberLock } from '@/api/member'
import { outboundCall } from '@/api/outbound'
import { getAuditTemplateList, deleteAuditTemplate } from '@/api/auditTemplate'

import { examUserInfo,updateUserInfo } from '@/api/kaowu/exam'

export default {
  name: 'MemberInformation',
  filters: {
    timeFilter(timestamp) {
      return parseTime(timestamp, '{y}-{m}-{d} {h}:{i}')
    }
  },
  props: ['id', 'uid'],
  data(){
    return {
      pickerOptions: {

      },
      details: '',
      apiUpload: window.global.RequestBaseUrl + "/kaowu/upload/uploadFile",
      dialogVisible: false,
      video_url: '',
      editDialog: false,
      edit_type: '',
      edit_index:'',
      options_audit: [],
      setAuditReason: '',
      dialPhone: '',
      dialName: '',
      meetDialogVisible: false,
      callDialogVisible: false,
      jobWanted: [],
      loading: true,
      is_display: false,
      auditTemplateId: '',
      auditTemplateList: {},
      addAuditTemplate: 0,
      addAuditTemplateDesc: '',
      canAddAuditTemplate: false
    }
  },
  watch: {
    is_display: {
      handler(newVal, oldVal) {
        const is_display = newVal === true ? 1 : 0;
        if (is_display != this.form.is_display) {
          this.form.is_display = is_display;
          this.submit('is_display')
        }
      },
    }
  },
  created () {
    this.userInfoDetails()
  },
  methods: {
    handleAvatarSuccess(res, file) {
      var index = this.edit_index
      this.details.rows[index].value = window.global.RequestHost  + res.data.relative_url.replace(/\\/g, '/');
    },

    init(){
      this.userInfoDetails()
    },
    choicJobWanted(){
      this.userInfoDetails(this.jobWanted)
    },
    callHandleClose(){
      this.callDialogVisible = false
    },
    meetHandleClose(){
      this.meetDialogVisible = false
    },
    clickDial(phone, name){
      this.$confirm('是否对【' + name + '】' + phone + ' 发起呼叫？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        outboundCall(
          { 'mobile': phone }
        ).then(res => {
          if (res.code == 200){
            this.meetDialogVisible = true
            this.dialPhone = phone
            this.dialName = name
          }
          if (res.code == 4040){
            this.callDialogVisible = true
          }
        }).catch((res) => {
        })
      }).catch(() => {

      })
    },
    submit(type){
      var data = null;
      var rows = this.details.rows
      for(var i in rows){
        if(rows[i].field == type){
          data = rows[i]
        }
      }
      var params = {id:this.id,rows:data}
      console.log()
      updateUserInfo(params)
        .then(res => {
          this.$message.success(res.message)
          this.editDialog = false
        }).catch(() => {

        })
    },
    locking(row) {
      var that = this
      let tip = ''
      let status = ''
      if (row.member_status == 1) {
        tip = '确定锁定该会员吗？'
        status = 0
      } else {
        tip = '确定解锁该会员吗？'
        status = 1
      }
      that
        .$confirm(tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          const param = {
            uid: row.uid,
            status
          }
          memberLock(param).then(response => {
            that.$message.success(response.message)
            this.userInfoDetails()
            return true
          })
        })
        .catch(() => { })
    },
    delResumeImg(){
      if (this.form.resume_img.length <= 0) {
        this.$message.error('请选择删除的作品')
        return false
      }
      this.$confirm('此操作将永久删除选中的信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          resumeImgDel({ 'id': this.form.resume_img }).then(response => {
            this.$message.success(response.message)
            this.userInfoDetails()
            return true
          }).catch(() => { })
        })
        .catch(() => { })
    },
    classify(){
      classify({ 'type': 'resumeAudit' }).then(res => {
        this.options_audit = res.data
      }).catch(() => {
      })
    },
    videoPlay(url){
      this.video_url = url
      this.dialogVisible = true
    },
    userInfoDetails(jobWanted){
      var start = ''
      var end = ''
      if (jobWanted){
        start = jobWanted[0]
        end = jobWanted[1]
      }
      examUserInfo({ 'id': this.id, 'start': start, 'end': end })
        .then(res => {
          console.log(res.data.info)
          this.details = res.data.info
          this.loading = false
        }).catch(() => {

        })
    },
    checkClick(id){
      if (this.form.resume_img.indexOf(id) == -1){
        this.form.resume_img.push(id)
      } else {
        this.form.resume_img.splice(this.form.resume_img.indexOf(id), 1)
      }
    },

    viewFile(url){
      window.location.href = url
    },
    handleEdit(item,index){
      let type = item.field
      console.log(type)
      if (type == 'examine'){
        if (this.form.resume_img.length <= 0) {
          this.$message.error('请选择审核的作品')
          return false
        }
      }
      if (type == 'audit') {
        this.form.examine = 0
        // 获取审核模板列表
        this.getAuditTemplateList()
        this.auditTemplateId = ''
        this.setAuditReason = ''
      }
      console.log(type)
      this.edit_type = type
      this.edit_index = index
      this.editDialog = true
    },
    // 获取审核模板列表
    getAuditTemplateList() {
      getAuditTemplateList({ type: 1 })
        .then(res => {
          this.auditTemplateList = res.data

          let maxTemplate = 6;
          let currentNum = this.auditTemplateList.length;
          if (currentNum >= maxTemplate) {
            this.addAuditTemplateDesc = '新增模板（最多可添加' + maxTemplate + '条，当前已添加' + currentNum + '条）';
            // 超过最大可添加就不能再添加模板了
            this.canAddAuditTemplate = true
          } else {
            let diffNum = maxTemplate - currentNum;
            this.addAuditTemplateDesc = '新增模板（最多可添加' + maxTemplate + '条，还可添加' + diffNum + '条）';
            this.canAddAuditTemplate = false
          }
          // 最后拼接一个默认选中项
          this.auditTemplateList.push({
            id: 0,
            content: '其他'
          })
          this.defaultSelectedAuditTemplate()
          this.addAuditTemplate = 0
        })
        .catch(() => {
        })
    },
    // 切换审核状态
    auditDataChange(){
      this.auditTemplateId = ''
      this.setAuditReason = ''
      this.defaultSelectedAuditTemplate()
    },
    // 删除审核模板
    deleteAuditTemplate(id) {
      this.$confirm('确定要删除此模板吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteAuditTemplate({ id: id })
            .then(res => {
              // 如果删除的模板当前已被选中就将选中值清空
              if (this.auditTemplateId == id) {
                this.auditTemplateId = ''
              }
              // 获取审核模板列表
              this.getAuditTemplateList()
            })
            .catch(() => {
            })
        })
        .catch(() => {
        })
    },
    // 选中审核模板事件
    selectedAuditTemplate() {
      // 选中模板后将模板内容放入到原因中
      if (this.auditTemplateId > 0 && this.auditTemplateList.length > 0) {
        this.auditTemplateList.forEach((item) => {
          if (item.id == this.auditTemplateId) {
            this.setAuditReason = item.content
            return
          }
        })
      } else {
        this.setAuditReason = ''
      }
    },
    // 默认选中审核模板
    defaultSelectedAuditTemplate(){
      if (this.form.examine == 2 && this.auditTemplateList.length > 0) {
        // 默认选中第一个模板
        this.auditTemplateId = this.auditTemplateList[0].id
        if (this.auditTemplateId > 0) {
          this.setAuditReason = this.auditTemplateList[0].content
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.package_date{
  width: 230px;
  margin-top: 10px;
  margin-bottom: 10px;
  height: 26px;
  float:right;
  ::v-deep .el-range-input{
    font-size: 12px;
  }
  ::v-deep .el-range__icon{
    line-height: 20px;
  }
  ::v-deep .el-range-separator{
    line-height: 18px;
  }
  ::v-deep .el-range__close-icon{
    line-height: 20px;
  }
}
.smalltip i {
  margin-right: 0px;
}
.smalltip{
  color:#c9c9c9;
  font-size: 12px;
}
.dial{
  position: relative;
  top:2px;
  width: 14px;
  height: 14px;
  display: inline-block;
  .disal_img{
    cursor:pointer;
    width: 14px;
    height: 14px;
    background: url('../../../../../assets/images/outbound/dial.png') no-repeat center;
  }
}
.meet{
  .box-content{
    .img{
      width: 150px;
      height:150px;
      text-align: center;
      margin-top: 40px;
      margin:0 auto;
      background: url('../../../../../assets/images/outbound/meet.png') no-repeat center;
    }
    .hu{
      text-align: center;
      margin-top: 30px;
      font-size: 15px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #949494;
    }
    .telephone{
      text-align: center;
      font-size: 30px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #333333;
      margin-top: 26px;
    }
    .company{
      text-align: center;
      margin-top:25px;
      font-size: 15px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #666666;
    }
    .tips{
      text-align: center;
      height: 80px;
      line-height: 80px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #959595;
    }
  }
}
.meet{
  ::v-deep .el-dialog__body{
    padding: 0px 0px 0px 0px;
    border-radius: 5px;
  }
  ::v-deep .el-dialog{
    border-radius: 16px;
  }
}
.call{
  .box-content{
    padding: 20px 30px 35px 30px;
    .advantage{
      .advantage-box{
        display: inline-block;
        width: 170px;
        .title{
          display: inline-block;
          float:left;
        }
        .img{
          display: inline-block;
          float:left;
          margin-right: 8px;
        }
      }
      margin-top: 25px;
    }
    .slogan{
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #FF550A;
      margin-top:24px;
    }
    .code{
      display: inline-block;
      margin-right: 30px;
      float: right;
      width: 117px;
      height: 117px;
      background: #FFFFFF;
      box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.14);
      border-radius: 8px;
      padding: 10px 10px;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .content{
      display: inline-block;
      float: left;
      .title1{
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FF550A;
      }
      .title2{
        margin-top: 18px;
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #555555;
      }
      .title3{
        width: 133px;
        height: 24px;
        background: #FF6929;
        border-radius: 3px;
        text-align: center;
        line-height: 24px;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
        margin-top: 23px;
      }
    }
  }
}
.call {
  ::v-deep .el-dialog__body {
    padding: 0px 0px 0px 0px;
    border-radius: 5px;
  }

  ::v-deep .el-dialog {
    border-radius: 16px;
  }
}
.overflow{
  display: inline-block;
  width: 68%;
  font-size: 14px;
  word-break: break-all;
  word-wrap: break-word;
}
.reason{
  display: inline-block;
  min-height: 60px;
}
.company_img{
  width: 100px;
  margin-right: 15px;
  height: 125px;
  position: relative;
  display: inline-block;
  .state{
    width: 100px;
    position: absolute;
    height:25px;
    font-size: 14px;
    text-align: center;
    line-height: 25px;
    bottom:15px;
    color: white;
    background: rgba(0,0,0,0.6);
  }
  .icon{
    position: absolute;
    top: 9px;
    right: -1px;
  }
  .check{
    position: absolute;
    top: 2px;
    left: 3px;
  }
}
.package_information{
  margin: 10px 20px 0px 20px;
  background: #fafcff;
  font-size: 14px;
  padding:15px;
  border-radius: 5px;
  .titles{
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
    line-height: 50px;
  }
  .content{
    width: 27%;
    margin-left: 20px;
    display: inline-block;
    margin-bottom: 15px;
  }
}
.clientInfo_wrapper{
  height: calc(100vh - 194px - 52px);
  overflow-y: auto;
  padding: 10px 0;
  .title{
    font-size: 14px;
    font-weight: 600;
    line-height: 50px;
    padding: 0 6px;
    border-bottom: 1px dotted #ebeef5;
  }
  .tag{
    margin-top: 5px;
    background: #ecf5ff;
    border-color: #b3d8ff;
    display: inline-block;
    padding: 0 10px;
    height: 24px;
    border-radius: 2px;
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    font-weight: 400;
    margin-right: 10px;
  }
  .clientInfo_box{
    padding:  0 30px;
  }
  .systeminfo_box{
    position: relative;
    padding:  0 30px;
  }
  .items{
    border-bottom: 1px solid #ebeef5;
  }
  .item{
    border-bottom: 1px dotted #ebeef5;
    display: flex;
    justify-content: space-between;
    .img{
      width: 250px;
      height:250px;
    }
    .info_width{
      width: 85%;
    }
    .info{
      display: flex;
      line-height: 20px;
      padding: 15px 6px;
      .auth{
        font-size: 14px;
        font-weight: 500;
        .icon_1 {
          color: #6EACE2;
        }
      }
      .clientinfo_type_1{
        color: #fe6135;
      }
      .label{
        width: 110px;
        color: #999;
        font-size: 14px;
        display: flex;
        align-items: center;
      }
      .text_width{
        width: 85%;
        .el-input{
          width: 100%;
        }
        .el-input__inner{
          padding: 0;
        }
      }
      .text{
        color: #000;
        font-size: 14px;
        .el-input{
          height: 28px;
        }
      }
    }
    .btn{
      display: flex;
      align-items: center;
    }
  }
}
.empty_texts{
  margin-bottom: 20px;
  height:100%;
  text-align: center;
  font-size: 14px;
  color:#d1cfcf;
  line-height: 30px;
}
.item_img_empty{
  margin-bottom: 20px;
  img{
    width: 120px;
    height:120px;
    margin-right: 15px;
    margin-top: 10px;
  }
}
.item_img{
  margin-bottom: 20px;
  margin-left: 116px;
  img{
    width: 120px;
    height:120px;
    margin-right: 15px;
    margin-top: 10px;
  }
}
.styles{
  border-bottom: 1px dotted #ebeef5;
}
.dial{
  position: relative;
  top:2px;
  left: 4px;
  width: 14px;
  height: 14px;
  display: inline-block;
  .disal_img{
    cursor:pointer;
    width: 14px;
    height: 14px;
    background: url('../../../../../assets/images/outbound/dial.png') no-repeat center;
  }
}
.meet{
  .box-content{
    .img{
      width: 150px;
      height:150px;
      text-align: center;
      margin-top: 40px;
      margin:0 auto;
      background: url('../../../../../assets/images/outbound/meet.png') no-repeat center;
    }
    .hu{
      text-align: center;
      margin-top: 30px;
      font-size: 15px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #949494;
    }
    .telephone{
      text-align: center;
      font-size: 30px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #333333;
      margin-top: 26px;
    }
    .company{
      text-align: center;
      margin-top:25px;
      font-size: 15px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #666666;
    }
    .tips{
      text-align: center;
      height: 80px;
      line-height: 80px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #959595;
    }
  }
}
.meet{
  ::v-deep .el-dialog__body{
    padding: 0px 0px 0px 0px;
    border-radius: 5px;
  }
  ::v-deep .el-dialog{
    border-radius: 16px;
  }
}
.call{
  .box-content{
    padding: 20px 30px 35px 30px;
    .advantage{
      .advantage-box{
        display: inline-block;
        width: 170px;
        .title{
          display: inline-block;
          float:left;
        }
        .img{
          display: inline-block;
          float:left;
          margin-right: 8px;
        }
      }
      margin-top: 25px;
    }
    .slogan{
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #FF550A;
      margin-top:24px;
    }
    .code{
      display: inline-block;
      margin-right: 30px;
      float: right;
      width: 117px;
      height: 117px;
      background: #FFFFFF;
      box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.14);
      border-radius: 8px;
      padding: 10px 10px;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .content{
      display: inline-block;
      float: left;
      .title1{
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FF550A;
      }
      .title2{
        margin-top: 18px;
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #555555;
      }
      .title3{
        width: 133px;
        height: 24px;
        background: #FF6929;
        border-radius: 3px;
        text-align: center;
        line-height: 24px;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
        margin-top: 23px;
      }
    }
  }
}
.call{
  ::v-deep .el-dialog__body{
    padding: 0px 0px 0px 0px;
    border-radius: 5px;
  }
  ::v-deep .el-dialog{
    border-radius: 16px;
  }
}
.item{
  border-bottom: 1px dotted #ebeef5;
  display: flex;
  justify-content: space-between;
  .img{
    width: 250px;
    height:250px;
  }
  .info_width{
    width: 85%;
  }
  .info{
    display: flex;
    line-height: 20px;
    padding: 15px 6px;
    .auth{
      font-size: 14px;
      font-weight: 500;
      .icon_1 {
        color: #6EACE2;
      }
    }
    .clientinfo_type_1{
      color: #fe6135;
    }
    .label{
      width: 110px;
      color: #999;
      font-size: 14px;
      display: flex;
      align-items: center;
    }
    .text_width{
      width: 85%;
      .el-input{
        width: 100%;
      }
      .el-input__inner{
        padding: 0;
      }
    }
    .text{
      color: #000;
      font-size: 14px;
      .el-input{
        height: 28px;
      }
    }
  }
  .btn{
    display: flex;
    align-items: center;
  }
}
.clientInfo_box{
  padding:  0 30px;
}

.audit_template_select{
  .el-select{
    width: 100% !important;
  }
}

.checkboxAddAuditTemplate{
  ::v-deep .el-checkbox__inner{
    border-radius: 50%;
  }
}

.multiline-text{
  white-space: normal;
  width: 330px;
}

.el-select-dropdown__item {
  font-size: 14px;
  padding: 0 20px;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: auto;
  line-height: 1.5;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  &:first-child{
    margin-top: 10px;
  }
}

.item-box{
  display: flex;
  justify-content: flex-start;
  box-sizing: border-box;
  padding-left: 50px;
  align-items: baseline;
  .reason{
    min-height: initial;
    width: 70px;
    text-align: right;
  }
  .el-select{
    width: 80% !important;
  }
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
